package cn.zn.framework.common.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.http.HttpStatus;

import java.io.Serializable;

@Data
@ApiModel("接口返回内容")
public class Result<T> implements Serializable {
    @ApiModelProperty("编码：0-成功")
    private int code = 0;
    @ApiModelProperty("消息：success")
    private String msg = "success";
    @ApiModelProperty("返回值")
    private T data;

    public static <T> Result<T> ok() {
        Result<T> result = new Result<>();
        return result;
    }

    public static <T> Result<T> ok(T t) {
        Result<T> result = new Result<>();
        result.setData(t);
        return result;
    }

    public static <T> Result<T> error() {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
    }

    public static <T> Result<T> error(String msg) {
        // 客户端错误-9400
        return error(9400, msg);
    }

    public static <T> Result<T> error(int code, String msg) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
